#include <iostream>

using namespace std;

int main(){
	
	int t;
	cin>>t;
	while(t--){
		int n,m;
		cin>>n>>m;
		string s,t;
		cin>>s>>t;
		if(n==m && s!=t){
			cout<<"NO"<<endl;
			continue;
		}
		int idx1=0,idx2=0;
		while(idx1<s.size() && idx2<t.size() && s[idx1]==t[idx2]){
			++idx1,++idx2;
		}
		string s1=s.substr(0,idx1);
		//cout<<s1<<endl;
		int dis=n-m;
		string tmp;
		bool flg=false;
		for(int i=idx1;i<s.size() && dis>0 && !flg;++i,--dis){
			tmp+=s[i];
			//cout<<t+tmp<<' '<<s1+s.substr(idx1+1)<<endl;
			if(t+tmp==s1+s.substr(i+1)){
				flg=true;
			}
		}
		if(flg){
			cout<<"YES"<<endl;
		}
		else{
			cout<<"NO"<<endl;
		}
	}
	return 0;
}
